/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servidor.auxiliar;


import common.Menssagem;
import common.RMITweetInterface;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ziza
 */
public class DataCliente {

    String nickname = "";
    boolean status = false;
    RMITweetInterface ligacao = null;
    ObjectOutputStream out = null;

    public DataCliente(RMITweetInterface ligacao) {
        this.ligacao = ligacao;
    }

    public DataCliente(ObjectOutputStream out) {
        this.out = out;
    }

    public RMITweetInterface getLigacao() {
        return ligacao;
    }

    public ObjectOutputStream getOut() {
        return out;
    }

    public String getNickname() {
        return nickname;
    }

    public boolean isStatus() {
        return status;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public void setOut(ObjectOutputStream out) {
        this.out = out;
    }

    public String mandaTweetFollerRMI(Menssagem sms){
        try {
            this.ligacao.recebeSMSInstatanea(sms);
            return "ok";
        } catch (RemoteException ex) {
            System.out.println("[ERRO]Remote: Erro no envio do tweet aos follers!\n"+ex.getMessage());
            return null;
        }
    }

    public String fazCanalClose(){
        if(out!=null){
            try {
                out.close();
                return "ok";
            } catch (IOException ex) {
                return null;
            }
        }
        else{
            if(ligacao!=null){
                ligacao = null;
                return "ok";
            }
            else
                return null;
        }
    }
}
